﻿using System.Linq;

namespace 自定义Linq方法
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var employees = new List<Employee>() {  
                new Employee(){ Id=1,Name="大虎",Age=28,Gender=1,Salary=8000}, 
                new Employee(){ Id=2,Name="翠花",Age=29,Gender=2,Salary=9000}, 
                new Employee(){ Id=3,Name="大壮",Age=30,Gender=1,Salary=10000}, 
                new Employee(){ Id=4,Name="铁柱",Age=31,Gender=1,Salary=11000}, 
                new Employee(){ Id=5,Name="阿强",Age=32,Gender=1,Salary=12000}, 
                new Employee(){ Id=6,Name="阿秀",Age=33,Gender=2,Salary=13000}, 
                new Employee(){ Id=7,Name="柱子",Age=40,Gender=1,Salary=14000}, 
            };
            //原始Linq
            //var count = employees.Count(c => c.Gender==2);
            //Console.WriteLine($"女性员工数：{count}");

            //var newEmployees = employees.Where(c => c.Salary>=10000);
            //foreach (var item in newEmployees)
            //{
            //    Console.WriteLine(item);
            //}

            var users = employees.Select(c => new User() { Name = c.Name, Age=c.Age }).ToList();
            foreach (var item in users)
            {
                Console.WriteLine(item);
            }


            //自定义Linq
            //var count = employees.MyCount(e => e.Gender==2);
            //Console.WriteLine($"女性员工数：{count}");

            //var newEmployees = employees.MyWhere(c => c.Salary>=10000);
            //foreach (var item in newEmployees)
            //{
            //    Console.WriteLine(item);
            //}

            //var users = employees.MySelect(c=> new User() { Name = c.Name, Age=c.Age });
            //foreach (var item in users)
            //{
            //    Console.WriteLine(item);
            //}

            Console.ReadKey();
        }
    }
}
